package com.irdstudio.efp.console.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.console.service.dao.CaStrategyCfgDao;
import com.irdstudio.efp.console.service.domain.CaStrategyCfg;
import com.irdstudio.efp.console.service.facade.CaStrategyCfgService;
import com.irdstudio.efp.console.service.vo.CaStrategyCfgVO;
/**
 * <p>ServiceImpl: CA加签策略配置表				<p>
 * @author chenqm1
 * @date 2018-06-09
 */
@Service("caStrategyCfgService")
public class CaStrategyCfgServiceImpl implements CaStrategyCfgService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(CaStrategyCfgServiceImpl.class);

	@Autowired
	private CaStrategyCfgDao caStrategyCfgDao;
	
	/**
	 * 新增操作
	 */
	public int insertCaStrategyCfg(CaStrategyCfgVO inCaStrategyCfgVo) {
		logger.debug("当前新增数据为:"+ inCaStrategyCfgVo.toString());
		int num = 0;
		try {
			CaStrategyCfg caStrategyCfg = new CaStrategyCfg();
			beanCopy(inCaStrategyCfgVo, caStrategyCfg);
			num = caStrategyCfgDao.insertCaStrategyCfg(caStrategyCfg);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(CaStrategyCfgVO inCaStrategyCfgVo) {
		logger.debug("当前删除数据条件为:"+ inCaStrategyCfgVo);
		int num = 0;
		try {
			CaStrategyCfg caStrategyCfg = new CaStrategyCfg();
			beanCopy(inCaStrategyCfgVo, caStrategyCfg);
			num = caStrategyCfgDao.deleteByPk(caStrategyCfg);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inCaStrategyCfgVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(CaStrategyCfgVO inCaStrategyCfgVo) {
		logger.debug("当前修改数据为:"+ inCaStrategyCfgVo.toString());
		int num = 0;
		try {
			CaStrategyCfg caStrategyCfg = new CaStrategyCfg();
			beanCopy(inCaStrategyCfgVo, caStrategyCfg);
			num = caStrategyCfgDao.updateByPk(caStrategyCfg);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inCaStrategyCfgVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public CaStrategyCfgVO queryByPk(CaStrategyCfgVO inCaStrategyCfgVo) {
		
		logger.debug("当前查询参数信息为:"+ inCaStrategyCfgVo);
		try {
			CaStrategyCfg queryCaStrategyCfg = new CaStrategyCfg();
			beanCopy(inCaStrategyCfgVo, queryCaStrategyCfg);
			CaStrategyCfg queryRslCaStrategyCfg = caStrategyCfgDao.queryByPk(queryCaStrategyCfg);
			if (Objects.nonNull(queryRslCaStrategyCfg)) {
				CaStrategyCfgVO outCaStrategyCfgVo = beanCopy(queryRslCaStrategyCfg, new CaStrategyCfgVO());
				logger.debug("当前查询结果为:"+ outCaStrategyCfgVo.toString());
				return outCaStrategyCfgVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<CaStrategyCfgVO> queryAllOwner(CaStrategyCfgVO caStrategyCfgVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<CaStrategyCfgVO> list = null;
		try {
			List<CaStrategyCfg> caStrategyCfgs = caStrategyCfgDao.queryAllOwnerByPage(caStrategyCfgVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ caStrategyCfgs.size());
			pageSet(caStrategyCfgs, caStrategyCfgVo);
			list = (List<CaStrategyCfgVO>) beansCopy(caStrategyCfgs, CaStrategyCfgVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<CaStrategyCfgVO> queryAllCurrOrg(CaStrategyCfgVO caStrategyCfgVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<CaStrategyCfg> caStrategyCfgs = caStrategyCfgDao.queryAllCurrOrgByPage(caStrategyCfgVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+caStrategyCfgs.size());
		List<CaStrategyCfgVO> list = null;
		try {
			pageSet(caStrategyCfgs, caStrategyCfgVo);
			list = (List<CaStrategyCfgVO>) beansCopy(caStrategyCfgs, CaStrategyCfgVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<CaStrategyCfgVO> queryAllCurrDownOrg(CaStrategyCfgVO caStrategyCfgVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<CaStrategyCfg> caStrategyCfgs = caStrategyCfgDao.queryAllCurrDownOrgByPage(caStrategyCfgVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ caStrategyCfgs.size());
		List<CaStrategyCfgVO> list = null;
		try {
			pageSet(caStrategyCfgs, caStrategyCfgVo);
			list = (List<CaStrategyCfgVO>) beansCopy(caStrategyCfgs, CaStrategyCfgVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	@Override
	public List<CaStrategyCfgVO> queryByLegalOrgCode(CaStrategyCfgVO caStrategyCfgVo) {
		logger.debug("根据法人机构查询当前参数信息为:");
		List<CaStrategyCfg> caStrategyCfgs = caStrategyCfgDao.queryByLegalOrgCode(caStrategyCfgVo);
		logger.debug("根据法人机构查询结果集数量为:"+ caStrategyCfgs.size());
		List<CaStrategyCfgVO> list = null;
		try {
			pageSet(caStrategyCfgs, caStrategyCfgVo);
			list = (List<CaStrategyCfgVO>) beansCopy(caStrategyCfgs, CaStrategyCfgVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}
}
